package com.nineclock.document.controller;

import com.nineclock.api.document.controller.AppDocControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.document.dto.*;
import com.nineclock.document.pojo.DocFolder;
import com.nineclock.document.service.AppDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AppDocController implements AppDocControllerApi {
    /**
     * 查询当前目录下的文件夹以及文件
     *
     * @param parentFoldId // 父目录Id
     * @return
     */
    @Autowired
    AppDocService appDocService;
    @GetMapping("/listFolderAndFile")
    @Override
    public Result<DocumentDto> findFolderAndFile(@RequestParam(value = "parentFoldId", defaultValue = "0") Long parentFoldId) {
        DocumentDto documentDto = appDocService.findFolderAndFile(parentFoldId);
        return Result.success(documentDto);
    }

    /**
     * 新建文件夹
     *
     //* @param name
     //* @param parentId
     * @return
     */
    @PostMapping("/insertFolder")
    @Override
    //public Result insertFolder(@RequestBody String name, @RequestBody Long parentId)
    public Result insertFolder(@RequestBody DocFolderDto docFolderDto) {
        appDocService.insertFolder(docFolderDto);
        return Result.success();
    }
    // 根据文档ID查询文档
    @GetMapping("/getFileByFileId")
    @Override
    public Result<DocFileDto> findDocFileById(Long id) {
        DocFileDto docFileDto = appDocService.findDocFileById(id);
        return Result.success(docFileDto);
    }

    // 分页查询协作者id及名字
    @GetMapping("/pagingCollaborations")
    @Override
    public Result<PageResult<DocumentUserDTO>> findCollaborationsByPage(@RequestParam("id") Long fileId, @RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pageSize", defaultValue = "7") Long pageSize) {
        PageResult<DocumentUserDTO> pageResult = appDocService.findCollaborationsByPage(fileId, page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 根据文档id获取员工列表
     * @param docId
     * @return
     */
    @GetMapping("/pagingUsers")
    @Override
    public Result<List<DocUserCollaborationDTO>> findCompanyUserByDocId(@RequestParam("id") Long docId) {
        List<DocUserCollaborationDTO> list = appDocService.findCompanyUsersByDocId(docId);
        return Result.success(list);
    }

}
